#include "Bullet.h"

CBullet::CBullet()
{
	_alive = true;
	_levelBullet = 1;
	_timeaLive.SetStartTime();
}

CBullet::CBullet(float ix, float iy, int itimeaLive, float ivx, float ivy, int ilevelBullet, double ialpha)
{
	_x0 = ix;
	_y0 = iy;
	_x = ix;
	_y = iy;
	_timeaLive = CTimer((double)itimeaLive);
	_vx = ivx;
	_vy = ivy;
	_alive = true;
	_levelBullet = ilevelBullet;
	_alpha = ialpha;
}

CBullet::CBullet(CBullet *iBullet)
{
	_x0 = iBullet->_x;
	_y0 = iBullet->_y;
	_x = iBullet->_x;
	_y = iBullet->_y;
	_timeaLive = iBullet->_timeaLive;
	_vx = iBullet->_vx;
	_vy = iBullet->_vy;
	_alive = iBullet->_alive;
	_levelBullet = iBullet->_levelBullet;
	_alpha = iBullet->_alpha;
}
bool CBullet::operator == (CBullet a)const
{
	if (_x != a._x || _y != a._y || _vx != a._vx || _vy != a._vy || _alive != a._alive || _timeaLive != a._timeaLive || _levelBullet != a._levelBullet)
		return false;
	else
		return true;
}

void CBullet::SetVelocity(float ivx, float ivy)
{
	_vx = ivx;
	_vy = ivy;
}

void CBullet::SetLocation(float ix, float iy)
{
	_x = ix;
	_y = iy;
}

bool CBullet::CheckALive()
{
	if (_timeaLive.ClockTrue())
	{
		_alive = false;
		return false;
	}

	return true;
}

void CBullet::Update()
{
	_x += _vx;
	_y += _vy;
}

void CBullet::Draw(CSprite *iSprite)
{
	iSprite->Render(_x, _y, 0, VIEW_PORT_Y);
}

CBullet::~CBullet()
{

}